package com.itboye.hutouben.activity.qianbao;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.hutouben.R;
import com.itboye.hutouben.base.BaseActivity;
import com.itboye.hutouben.base.MyApplcation;
import com.itboye.hutouben.presenter.SysTemMessgelPresenter;
import com.itboye.hutouben.presenter.UserPresenter;
import com.itboye.hutouben.util.ByAlert;
import com.itboye.hutouben.util.Const;
import com.itboye.hutouben.util.IsUtilUid;
import com.itboye.hutouben.util.SPUtils;
import com.itboye.hutouben.volley.ResultEntity;

import java.util.Observable;
import java.util.Observer;

/**
 * 添加银行卡3
 */
public class AddBankCardThreeActivity extends BaseActivity implements Observer {
    TextView add_shap_title_tv;
    ImageView close_icon;
    EditText add_bank03_code;
    TextView add_bank03_ok;
    SysTemMessgelPresenter presenter;
    String names,model;
    String xingming;
    String yhk_type;
    String phone;

    UserPresenter userPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_bank_card_three);
        add_shap_title_tv.setText(R.string.bind_yinhangka);
        presenter=new SysTemMessgelPresenter(this);
        userPresenter=new UserPresenter(this);
        names = getIntent().getStringExtra("name");
        xingming= getIntent().getStringExtra("xingming");
        yhk_type = getIntent().getStringExtra("yhk_type");
        phone = getIntent().getStringExtra("phone");
        presenter.onBangDinType();
        model = (String) SPUtils.get(MyApplcation.ctx, null, Const.MOBILE, "");

    }

    @Override
    protected void onInit() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        Intent intent=null;
        switch (v.getId()) {
            case R.id.close_icon:
                finish();
                break;
            case R.id.add_bank03_ok:
                if (add_bank03_code.getText().toString() == null || add_bank03_code.getText().toString().equals("")) {
                    ByAlert.alert("请填写验证码");
                } else {

                    showProgressDialog("请稍后...", true);
                    userPresenter.YanZhengverificationCode("+86",model,add_bank03_code.getText().toString(),2+"");
                    Log.d("werwerwertwetwaet",names+"");
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            IsUtilUid.tianjia(entity);
            if(entity.getEventType()==UserPresenter.yanzheng_code_success){

                presenter.onByWalletBind(IsUtilUid.isUid(), names, "6197",yhk_type,xingming);
            }
            if(entity.getEventType()==UserPresenter.yanzheng_code_fail){
                ByAlert.alert(entity.getData());
            }
            if (entity.getEventType() == presenter.BANG_success) {
                ByAlert.alert(entity.getData());
                finish();

                // 发送广播通知界面结束
                Intent intent1 = new Intent("tianjia.exit");
                sendBroadcast(intent1);
            }
            if (entity.getEventType() == presenter.BANG_fail) {
                ByAlert.alert(entity.getData());

            }
        }
        try {
            closeProgressDialog();
        } catch (Exception e) {
        }
    }
}
